
"use strict";

//=========================
// 引入子组建和子组建reducer
//=========================
export const USER_LOGIN = "USER_LOGIN" ;
export const LoginReducers = (state = {}, action)=>{
    switch (action.type){
        case USER_LOGIN:
            if (action.data.status === "0") {
                let _data = action.data.data;
                sessionStorage.setItem("id", _data.id);
                sessionStorage.setItem("messageCount", action.data.messageCount ? action.data.messageCount : "0");
                sessionStorage.setItem("displayName", _data.displayName);
                sessionStorage.setItem("phone", _data.phone);
                sessionStorage.setItem("authenticationStatus", _data.authenticationStatus);
                sessionStorage.setItem("headUrl", _data.headUrl ? _data.headUrl : "");
                sessionStorage.setItem("selectPage", "1");
                sessionStorage.setItem("userKeyId",_data.updatedUser);
                if(action.data.data.headUrl==null|| action.data.data.headUrl==""){
                    sessionStorage.setItem("headUrlValue","0")
                }else{
                    sessionStorage.setItem("headUrlValue","1")
                }
            }
            state = action.data ;
        default :
            return state ;
    }
} ;

export const mapStateToProps = state =>{
    return {
        user : state.login,
    }
} ;

export const mapDispatchToProps = dispatch =>{
    return{
        change : (e)=>{dispatch({type:USER_LOGIN,data:e})}
    }
} ;


